package top.gbiot.scan.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import lombok.Getter;
import top.gbiot.scan.entity.Student;

import java.util.ArrayList;
import java.util.List;

/**
 * .
 *
 * @Author Chenglin Zhu
 * @Date 2021/7/2 3:16 下午
 */
//使用EasyExcel进行学生信息的数据导入

/**
 * 学生读取类
 *
 * @author CL
 *
 */
public class StudentListener extends AnalysisEventListener<Student> {

    @Getter
    private List<Student> studentList = new ArrayList<Student>();

    public StudentListener() {
        super();
        studentList.clear();
    }

    /**
     * 每一条数据解析都会调用
     */
    @Override
    public void invoke(Student student, AnalysisContext context) {
        studentList.add(student);
    }

    /**
     * 所有数据解析完成都会调用
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {

        for (Student student : studentList) {
            System.out.println(student);
        }
        //studentList.forEach(System.out::println);

    }

}